//
//  HMSlideViewCell.m
//  02-图片轮播器
//
//  Created by 教师机 on 16/9/18.
//  Copyright © 2016年 itheima. All rights reserved.

#import "HMSlideViewCell.h"
#import "UIImageView+WebCache.h"

@interface HMSlideViewCell ()
@property(nonatomic,weak)UIImageView * imageView;
@end

@implementation HMSlideViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

#pragma  mark -  重写setter方法,用真实的数据赋值
/**
 *  重写setter方法,用真实的数据赋值
 */
- (void)setUrl:(NSURL *)url {
    _url = url;
    
    
    [_imageView sd_setImageWithURL:url placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        _imageView.image = image;
    }];
    
//    //1.把url转换成NSData
//    NSData * data = [NSData dataWithContentsOfURL:url];
//    //2.根据data创建图像
//    UIImage * image = [UIImage imageWithData:data];
//    
//    //3.把这个真实的image赋值给这个cell的imageView
//    _imageView.image = image;
}

#pragma mark - 设置界面
- (void)setupUI {
    //1.创建图像视图
    UIImage * image = [UIImage imageNamed:@"Home_Scroll_02.jpg"];
    
    UIImageView * imageV = [[UIImageView alloc]initWithFrame:self.bounds];
    imageV.image = image;
    
    //2.图片的填充模式
    imageV.contentMode = UIViewContentModeScaleAspectFill;//以图片的最小边作为标准,等比例缩放,居中.
    imageV.clipsToBounds = YES; //将图像外面的内容给剪掉
    
    //在collectionView的cell中添加控件,是可以直接用self的.
    //如果你是往tableView的cell中添加控件,就必须要往cell的contentView中添加.
    [self addSubview:imageV];
    
    //2.用属性记录这个iamgeV
    _imageView = imageV;
}

@end
